home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / dev / src / wangisrc.lha / wangi / z / ea / machine.c < prev    next >
C/C++ Source or Header  |  1996-02-04  |  4KB  |  182 lines

  1. /*************************************************************************
  2.  *
  3.  * ea/deea
  4.  *
  5.  * Copyright ©1995 Lee Kindness and Evan Tuer
  6.  * cs2lk@scms.rgu.ac.uk
  7.  *
  8.  * machine.c
  9.  *  Initilisation code plus any other machine dependant code.
  10.  */
  11.  
  12. #include "machine.h"
  13.  
  14.  
  15. #ifdef AMIGA
  16.  
  17. /*************************************************************************
  18.  * msprintf() - Equivalent to sprintf(). Implemented using the exec RawDoFmt
  19.  *  command. Note that "\x16\xC0\x4E\x75" represents:
  20.  *
  21.  *    move.b  d0,(a3)+
  22.  *    rts
  23.  */
  24.  
  25. void msprintf(char *buffer, char *format, ...)
  26. {
  27.     RawDoFmt(format, (APTR)(&format+1), (void (*))"\x16\xC0\x4E\x75", buffer);
  28. }
  29.  
  30. #endif /* AMIGA */
  31.  
  32.  
  33. /*************************************************************************
  34.  * InitSystem() - Called from main() to initilise and check any system
  35.  *  options or dependancies.
  36.  */
  37.  
  38. int InitSystem( void )
  39. {
  40. #ifdef AMIGA
  41.     if( (((struct Library *)DOSBase)->lib_Version >= 36) &&
  42.         (((struct Library *)SysBase)->lib_Version >= 36) )
  43.         return( 1 );
  44.     else
  45.         return( 0 );
  46. #else
  47.     return( 1 );
  48. #endif
  49. }
  50.  
  51.  
  52. /*************************************************************************
  53.  * FreeSystem() - Called from main() to delalocate anything allocated
  54.  *  by InitSystem.
  55.  */
  56.  
  57. void FreeSystem( void )
  58. {
  59. }
  60.  
  61.  
  62. /*************************************************************************
  63.  * GeteaArgs() - Parse command line arguments for ea
  64.  */
  65.  
  66. #define ARG_CSOURCE argv[1]
  67. #define ARG_CDEST argv[2]
  68. #define NUM_CARGS 3
  69.  
  70. struct Args *GeteaArgs(int argc, char **argv)
  71. {
  72.     struct Args *args = NULL;
  73. #ifdef AMIGA
  74. #define EA_TEMP "SOURCE/A,DESTINATION/A"
  75. #define OPT_CSOURCE 0
  76. #define OPT_CDEST 1
  77. #define OPT_CMAX 2
  78.     if( args = (struct Args *)mmalloc(sizeof(struct Args)) )
  79.     {
  80.         STRPTR argsa[OPT_CMAX] = {0, 0};
  81.         
  82.         if( args->arg_RAHandle = ReadArgs(EA_TEMP, (LONG *)&argsa, NULL) )
  83.         {
  84.             args->arg_Filename = argsa[OPT_CSOURCE];
  85.             args->arg_Dest = argsa[OPT_CDEST];
  86.         } else
  87.         {
  88.             mfree((char *)args);
  89.             args = NULL;
  90.             PrintFault(IoErr(), "ea");
  91.         }
  92.     }
  93. #else
  94.     if( argc == NUM_CARGS )
  95.     {
  96.         if( args = (struct Args *)mmalloc(sizeof(struct Args)) )
  97.         {
  98.             args->arg_Filename = ARG_CSOURCE;
  99.             args->arg_Dest = ARG_CDEST;
  100.         }
  101.     } else
  102.         mprintf("Usage:\n ea <source> <destination>\n");
  103. #endif    
  104.     return( args );
  105. }
  106.  
  107.  
  108. /*************************************************************************
  109.  * FreeeaArgs() - Free Arguments for ea
  110.  */
  111.  
  112. void FreeeaArgs(struct Args *args)
  113. {
  114.     if( args )
  115.     {
  116. #ifdef AMIGA
  117.         if( args->arg_RAHandle )
  118.             FreeArgs(args->arg_RAHandle);
  119. #endif
  120.         mfree((char *)args);
  121.     }    
  122. }
  123.  
  124.  
  125. /*************************************************************************
  126.  * GetdeeaArgs() - Parse command line arguments for deea
  127.  */
  128.  
  129. #define ARG_DSOURCE argv[1]
  130. #define NUM_DARGS 2
  131.  
  132. struct Args *GetdeeaArgs(int argc, char **argv)
  133. {
  134.     struct Args *args = NULL;
  135. #ifdef AMIGA
  136. #define DEEA_TEMP "SOURCE/A"
  137. #define OPT_DSOURCE 0
  138. #define OPT_DMAX 1
  139.     if( args = (struct Args *)mmalloc(sizeof(struct Args)) )
  140.     {
  141.         STRPTR argsa[OPT_DMAX] = {0};
  142.         
  143.         if( args->arg_RAHandle = ReadArgs(DEEA_TEMP, (LONG *)&argsa, NULL) )
  144.         {
  145.             args->arg_Filename = argsa[OPT_DSOURCE];
  146.         } else
  147.         {
  148.             mfree((char *)args);
  149.             args = NULL;
  150.             PrintFault(IoErr(), "deea");
  151.         }
  152.     }
  153. #else
  154.     if( argc == NUM_DARGS )
  155.     {
  156.         if( args = (struct Args *)mmalloc(sizeof(struct Args)) )
  157.         {
  158.             args->arg_Filename = ARG_DSOURCE;
  159.         }
  160.     } else
  161.         mprintf("Usage:\n deea <source>");
  162. #endif    
  163.     return( args );
  164. }
  165.  
  166.  
  167. /*************************************************************************
  168.  * FreedeeaArgs() - Free Arguments for deea
  169.  */
  170.  
  171. void FreedeeaArgs(struct Args *args)
  172. {
  173.     if( args )
  174.     {
  175. #ifdef AMIGA
  176.         if( args->arg_RAHandle )
  177.             FreeArgs(args->arg_RAHandle);
  178. #endif
  179.         mfree((char *)args);
  180.     }    
  181. }
  182.